import { post, upload } from './service-base';

/**
 * 查询入驻信息
 * https://h5-fe-backend.meitunmama.com/document?id=41_142-41&namespace=front&tab=api
 */
export const queryEnterInfo = (params: { merchantId: number }) => {
  return post('/starsports/merchant/queryEnterInfo', params).then(comak);
};

/**
 * 上传图片
 * https://h5-fe-backend.meitunmama.com/document?id=41_142-41&namespace=front&tab=api
 */
export const uploadFile = (params: FormData, progress) => {
  return upload('/starsports/merchant/uploadFile', params, progress).then(
    comak
  );
};

/**
 * 查询银行列表
 * https://h5-fe-backend.meitunmama.com/document?id=41_143-41&namespace=front&tab=api
 */
export const queryBanks = () => {
  return post('/starsports/merchant/queryBanks').then(comak);
};

/**
 * 查询银行支行列表
 * https://h5-fe-backend.meitunmama.com/document?id=41_144-41&namespace=front&tab=api
 */
export const querySubBanks = (params: {
  pBankId?: string;
  subBankName?: string;
  province?: string;
  city?: string;
  area?: string;
  pageNo?: number;
  pageSize?: number;
}) => {
  return post('/starsports/merchant/querySubBanks', params).then(comak);
};

function comak(res) {
  if (!res?.data?.success) {
    return Promise.reject(res?.data?.message);
  }
  return res?.data;
}

/**
 * 商家入驻
 * https://h5-fe-backend.meitunmama.com/document?id=41_140-41&namespace=front&tab=api
 */
export const enter = (params: {
  merchantId?: number;
  merchantStatus: number;
  merchantName: string;
  managerWxCode: string;
  tradeMarkAuthorization?: string;
  businessLicense: string;
  companyName: string;
  socialCreditCode: string;
  legalPersonIdCardFront: string;
  legalPersonIdCardBack: string;
  legalPersonIdCard: string;
  legalPersonIdCardExpireTimeStr: string;
  legalPersonName: string;
  legalPersonEmail: string;
  accountType: string;
  cardOwnerName: string;
  bankName: string;
  bankBranchName: string;
  bankCity: string;
  bankAccount: string;
  bankLicense: string;
}) => {
  return post('/starsports/merchant/enter', params).then(comak);
};
